package com.shujia.day16;

public class Code01ThreadGroup {

    public static void main(String[] args) {

        /*
            线程组：
                Thread 构造方法：
                     public Thread(ThreadGroup group, String name)
                     public Thread(ThreadGroup group, Runnable target, String name)
         */

        // public ThreadGroup(String name)
        ThreadGroup threadGroup1 = new ThreadGroup("帅哥组");
        ThreadGroup threadGroup2 = new ThreadGroup("美女组");


//        thread1.getThreadGroup()


        Thread thread3 = new Thread(threadGroup2, new MyThread(), "黄晓敏");



        thread3.start();
//        try {
//            thread3.join();

//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }


        Thread thread1 = new Thread(threadGroup1, new MyThread(), "张东东");
        Thread thread2 = new Thread(threadGroup1, new MyThread(), "唐彬");
        threadGroup1.setDaemon(true);  // 将帅哥组的线程设置成守护组
        thread1.start();
        thread2.start();


    }
}


class MyThread implements Runnable {

    public MyThread() {
    }

    @Override
    public void run() {

        for (int i = 1; i <= 1000; i++) {
            if (!Thread.currentThread().getName().equals("黄晓敏")) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }

            System.out.println(Thread.currentThread().getName() + "说了" + i + "次属于" + Thread.currentThread().getThreadGroup().isDaemon() + "组"+Thread.currentThread().isDaemon());
        }
        Thread.currentThread().stop();
        Thread.currentThread().getThreadGroup().stop();
    }
}
